const useListeningFolderAdd = (initInfo, treeRef, FolderAddRef, uploadSourceRef, initFolder) => {
  // 显示新建文件夹弹窗
  const showFolderAddDialog = item => {
    FolderAddRef.value.showDialog(item)
  }

  // 显示新建文件夹弹窗 (根据当前所在文件夹层级新建文件夹)
  const newFolderAdd = () => {
    if (initInfo.value.isRecycle) {
      showFolderAddDialog(null)
    } else {
      const activeNode = treeRef.value.getCheckedNodes()
      showFolderAddDialog(activeNode[0])
    }
  }

  // 显示新建文件夹弹窗 （树结构节点右键点击）
  const folderAddRightClick = () => {
    initInfo.value.isContextmenuClick = true
    showFolderAddDialog(initInfo.value.rightClickFolder)
  }

  // 新建文件夹弹窗关闭后，初始化部分参数
  const folderAddDialogClose = () => {
    initInfo.value.isContextmenuClick = false
    initInfo.value.rightClickFolder = null
  }

  // 更新上传资源弹窗中文件夹的选中状态
  const updateFolderChecked = v => {
    initInfo.value.form.folder_id = v.id
    initInfo.value.isRecycle = false
    initInfo.value.isCard = initInfo.value.isOldCard
    initFolder()
    if (initInfo.value.isUploadDialogShow) {
      uploadSourceRef.value.updateTreeSelected(v)
    }
  }

  return {
    showFolderAddDialog,
    newFolderAdd,
    folderAddRightClick,
    folderAddDialogClose,
    updateFolderChecked
  }
}
export default useListeningFolderAdd
